Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer wrapping for FFI clients. #2906

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nihohit
Copy link
Contributor

@nihohit nihohit commented Dec 31, 2024

Use Arc instead of Box to wrap the ClientAdapter, so that the lifetime of the adapter will be extended even in cases where the client is closed during commands. This also saves on using as usize conversions to the pointer, which cause provenance to be lost and might lead to undefined behavior.
The memory cost of this change is increasing the allocation of the client by one pointer size, and the runtime cost is 4 atomic increments/decrements per command.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@nihohit nihohit requested a review from a team as a code owner December 31, 2024 17:52
@nihohit nihohit force-pushed the pointers branch 3 times, most recently from f0dd565 to 47b8318 Compare December 31, 2024 18:49
csharp/lib/src/lib.rs Show resolved Hide resolved
csharp/lib/src/lib.rs Show resolved Hide resolved
csharp/lib/src/lib.rs Outdated Show resolved Hide resolved
go/src/lib.rs Outdated Show resolved Hide resolved
@nihohit
Copy link
Contributor Author

nihohit commented Jan 19, 2025

@Yury-Fridlyand @jonathanl-bq does this require more changes?

@Yury-Fridlyand
Copy link
Collaborator

I'm still lacking rust knowledge to assess. Summoning @ikolomi to give a bless.

csharp/lib/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jonathanl-bq jonathanl-bq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the one documentation suggestion, looks good to me.

Use `Arc` instead of `Box` to wrap the `ClientAdapter`, so that the lifetime of the adapter will be extended even in cases where the client is closed during commands.
This also saves on using `as usize` conversions to the pointer, which cause provenance to be lost and might lead to undefined behavior.

Signed-off-by: Shachar Langbeheim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants